function DecodingProbability_plotter()

clear all
close all
clc

% uncomment as necessary
% load('uep_ew_analytic_g1_03_g2_07')
% load('uep_ew_analytic_g1_04_g2_06')
load('uep_ew_analytic_g1_05_g2_05')


% Plot nice graph!
hold all

% Linespec options here
% http://www.mathworks.se/help/techdoc/ref/linespec.html

plotter(l1_prob_1,l2_prob_1,T_min,T_step,T_max,K1,K2,q(1));
legend_h=plotter(l1_prob_2,l2_prob_2,T_min,T_step,T_max,K1,K2,q(2));

% Set proper legend
label_1=strcat('L1, \Gamma_1=',num2str(g(1)),', FF(2^1)');
label_2=strcat('L2, \Gamma_1=',num2str(g(1)),', FF(2^1)');
label_3=strcat('L1, \Gamma_1=',num2str(g(1)),', FF(2^8)');
label_4=strcat('L2, \Gamma_1=',num2str(g(1)),', FF(2^8)');
set(legend_h,'String',[label_1;label_2;label_3;label_4],'location','SouthEast')
set(legend_h,'interpreter','tex')

% Save plot
figname=strcat('uep_ew_analytic','_g1_0',num2str(g(1)*10),'_g2_0',num2str(g(2)*10),'.eps');
print(gcf,'-deps',figname)


end

% Plotter for a nice graph!
function legend_h = plotter(l1_prob,l2_prob,T_min,T_step,T_max,K1,K2,q)

% Replace 0 with NaN in (l1_prob,l2_prob) for prettier plot
for k=1:length(l1_prob)
    
    if l1_prob(k)==0
        l1_prob(k)=NaN;
    end
end

for k=K2:length(l2_prob)
    if l2_prob(k)==0
        l2_prob(k)=NaN;
    end
    
end


% Plotting
figure(1)

if q ==2^1
    l1_style='s';
    l2_style='s';
else
    l1_style='o';
    l2_style='o';
end

% Legend fix
plot(-1,-1,'-s',-1,-1,'--s',-1,-1,'-o',-1,-1,'--o');

plot(1:length(l1_prob),l1_prob,'-','Color','k','MarkerSize',4)
plot(4:4:length(l1_prob),l1_prob(4:4:end),l1_style,'Color','k','MarkerSize',4)

plot(1:length(l2_prob),l2_prob,'--','Color','k','MarkerSize',4)
plot(4:4:length(l2_prob),l2_prob(4:4:end),l2_style,'Color','k','MarkerSize',4)

% Plot annotation
grid('on')
pbaspect([2.5 1 1])
legend_h = legend('location','NorthWest');
xlabel('Total number of received packets [-]')
ylabel('Decoding probability [-]')
set(gca,'XTick',0:10:T_max)
set(gca,'YTick',0:0.1:1)
xlim([T_min T_max])
ylim([0 1])

end

